'''
Created on Feb 21, 2013

@author: Justin
'''
import pygame, math, random
from pygame.locals import *
from unit import Unit
from images import *


class Enemy (Unit):

    container = pygame.sprite.Group()

    def __init__ (self, screen_rect, player, image=None):
        Unit.__init__(self, self.container)

        self.screen_rect = screen_rect
        self.player = player
        self.rect = Rect(0, random.randint(0, screen_rect.height), 50, 50)
        if not image:
            self.image = pygame.Surface((self.rect.width, self.rect.height))
            self.image.fill(Color(255,0,0))
        else:
            self.image = image
        self.angle = math.pi/2

    def move (self, time_passed):
        
        return (round(math.sin(self.angle) * time_passed * self.speed, 1),
                round(math.cos(self.angle) * time_passed * self.speed, 1))

    def update (self, time_passed):

        self.rect.move_ip(self.move(time_passed))
        if self.rect.left >= self.screen_rect.width:
            self.player.health -= 1
            self.kill(); del self


class SwampEnemy (Enemy):
    
    def __init__ (self, screen_rect, player):
        Enemy.__init__(self, screen_rect, player, SWAMP_ENEMY)

